package org.devocean.groupbuying.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;


@Entity
public class Discount{

	@Id
	@GeneratedValue
	private Integer discountID;
	private Double discountValue;
	private Double discountPrice;

//	@Column(columnDefinition="default '0'")
	private Double merchentDiscount;
	private Double commission;
	
//	@Column(columnDefinition="default '0'")
	private Integer maxPurchasePerClient;

	@OneToOne(cascade = CascadeType.REMOVE,mappedBy = "discount", fetch = FetchType.LAZY)
	private Voucher voucher;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "formulaID", referencedColumnName = "formulaID", nullable = false)
	private Formula formula;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "dealID", referencedColumnName = "dealID", nullable = false)
	private Deal deal;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "discount")
	private Set<PurchaseItem> purchaseItems = new HashSet<PurchaseItem>();

	public Integer getDiscountID() {
		return discountID;
	}

	public void setDiscountID(Integer discountID) {
		this.discountID = discountID;
	}

	public Double getDiscountValue() {
		return discountValue;
	}

	public void setDiscountValue(Double discountValue) {
		this.discountValue = discountValue;
	}

	public Double getDiscountPrice() {
		return discountPrice;
	}

	public void setDiscountPrice(Double discountPrice) {
		this.discountPrice = discountPrice;
	}

	public Double getMerchentDiscount() {
		return merchentDiscount;
	}

	public void setMerchentDiscount(Double merchentDiscount) {
		this.merchentDiscount = merchentDiscount;
	}

	public Double getCommission() {
		return commission;
	}

	public void setCommission(Double commission) {
		this.commission = commission;
	}

	public Voucher getVoucher() {
		return voucher;
	}

	public void setVoucher(Voucher voucher) {
		this.voucher = voucher;
	}

	public Formula getFormula() {
		return formula;
	}

	public void setFormula(Formula formula) {
		this.formula = formula;
	}

	public Deal getDeal() {
		return deal;
	}

	public void setDeal(Deal deal) {
		this.deal = deal;
	}

	public Set<PurchaseItem> getPurchaseItems() {
		return purchaseItems;
	}

	public void setPurchaseItems(Set<PurchaseItem> purchaseItems) {
		this.purchaseItems = purchaseItems;
	}

	public Integer getMaxPurchasePerClient() {
		return maxPurchasePerClient;
	}

	public void setMaxPurchasePerClient(Integer maxPurchasePerClient) {
		this.maxPurchasePerClient = maxPurchasePerClient;
	}

	@Override
	public String toString() {
		return "Discount [discountID=" + discountID + ", discountValue="
				+ discountValue + ", discountPrice=" + discountPrice
				+ ", merchentDiscount=" + merchentDiscount + ", commission="
				+ commission + ", maxPurchasePerClient=" + maxPurchasePerClient
				+ "]";
	}
}
